#coding=utf-8
#author :sh
import numpy as np
import cv2
import time


lower_blue = np.array([0,0,0])
upper_blue = np.array([170,255,46])
cap = cv2.VideoCapture(0)

###########################主图像处理函数############################################
def main():
	while(True):
		ret, frame = cap.read()
		gray   = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
		gray   = cv2.medianBlur(gray,5)
		# ret,thresh=cv2.threshold(gray,160,255,cv2.THRESH_BINARY)
		th1 = cv2.adaptiveThreshold(gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,3,2)
		cv2.imshow("gray",gray)
		cv2.imshow("th1",th1)
		if cv2.waitKey(1) & 0xFF == ord('q'):
			break
	cap.release()
	cv2.destroyAllWindows()
######################################################################################


###########函数入口###################################################################
if __name__=='__main__':
	try:
		main()
	except KeyboardInterrupt:
		print "hello"